<?php
class Silk_Metas extends Silk_Gateway
{

    protected $_dao_class = 'Silk_Dao_Meta';

    protected $_model_class = 'Silk_Meta';

    protected $_primary_key = 'meta_id';

    public function getObject($pMeta)
    {
        $meta = $this->getModelObject($pMeta);

        $Objects = new Silk_Objects();

        return $Objects->fetch($meta->object_id);
    }

    public function getSite($pMeta)
    {
        $meta = $this->getModelObject($pMeta);

        $Sites = new Silk_Sites();

        return $Sites->fetch($meta->site_id);
    }

    public function getTranslations($pMeta)
    {
        $meta_id = $this->getModelObjectId($pMeta);

        $Translations = new Silk_Translations();

        return $Translations->getTranslationsForMeta($meta_id);
    }

    public function getMetasForObject($pObjectId){
	return $this->fetch(array('object_id' => $pObjectId));
    }

    public function getModelCollection($pMetas){
	if ($pMetas instanceof Silk_Model_Collection)
	    return $pMetas;
	else if (is_array($pMetas)){
	    $metas = array();

	    foreach ($pMetas as $key => $m){
		if ($m instanceof Silk_Meta){
		    $metas[] = $m;
		} else if (is_array($m)){
		    $metas[] = array(
			'name' => $m['name'],
			'value' => $m['value']
		    );
		} else {
		    $metas[] = array(
			'name' => $key,
			'value' => $m
		    );
		}
	    }
	    return new $this->_model_collection_class($metas, $this, $this->_model_class);
	}
    }
}

 ?>